package com.project.service.impl;

import com.project.bean.RecordBean;
import com.project.mapper.IRecordMapper;
import com.project.mapper.IRoomMapper;
import com.project.service.IRecordService;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class RecordServiceImpl extends BaseService implements IRecordService {


    @Override
    public List<RecordBean> findById(Integer roomId) {
        SqlSession session = this.getSession();
        IRecordMapper mapper = session.getMapper(IRecordMapper.class);
        List<RecordBean> list = mapper.findById(roomId);
        session.close();
        return list;
    }

    @Override
    public void add(RecordBean record,Integer roomId) {
        SqlSession session = this.getSession();
        IRecordMapper mapper = session.getMapper(IRecordMapper.class);
        mapper.add(record,roomId);
        session.commit();
        session.close();
    }

    @Override
    public void ProcessingRecord(Integer recId, Integer roomId) {
        SqlSession session = this.getSession();
        IRecordMapper mapper = session.getMapper(IRecordMapper.class);
        mapper.updateRecordState(recId);
        if (mapper.findByRoomId(roomId)==0){
            IRoomMapper mapper1=session.getMapper(IRoomMapper.class);
            mapper1.updateRoomState(roomId);
        }
        session.commit();
        session.rollback();
        session.close();
    }
}
